/*
Welcome to Keystone! This file is what keystone uses to start the app.

It looks at the default export, and expects a Keystone config object.

You can find all the config options in our docs here: https://keystonejs.com/docs/apis/config
*/

import {config} from '@keystone-next/keystone';
// Look in the schema file for how we define our lists, and how users interact with them through graphql or the Admin UI
import {lists} from './schema';
// Keystone auth is configured separately - check out the basic auth setup we are importing from our auth file.
import {session, withAuth} from './auth';

export default withAuth(
    // Using the config function helps typescript guide you to the available options.
    config({
        // the db sets the database provider - we're using sqlite for the fastest startup experience
        db: {
            provider: 'postgresql',
            url: 'postgres://pojie3921:iR3eebJnpBTL@47.101.185.143:5432/test',
            onConnect: async context => {
                console.log('postgresql数据连接成功')
            },
            // 可选的高级配置
            idField : { kind : 'uuid' } ,
        },
        // This config allows us to set up features of the Admin UI https://keystonejs.com/docs/apis/config#ui
        ui: {
            // For our starter, we check that someone has session data before letting them see the Admin UI.
            isAccessAllowed: (context) => !!context.session?.data,
        },
        lists,
        session,
        server: {
            cors:true,
            port: 3000,
            maxFileSize: 200 * 1024 * 1024,
            healthCheck: true,
            extendExpressApp: (app, createContext) => {
                app.get('/api/_version', (req, res) => {
                    res.send('v6.0.0-rc.2');
                });
            },
        }
    })
);
